package com.xckj.teacher.ui.adapter

import android.annotation.SuppressLint
import android.graphics.drawable.Drawable
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xckj.teacher.R
import com.xckj.teacher.bean.Group
import com.xckj.teacher.bean.Student


class ClassItemAdapter(data: MutableList<Group>, var student: (Student) -> Unit) :
    BaseQuickAdapter<Group, BaseViewHolder>(
        R.layout.item_class_title, data
    ) {


    @SuppressLint("UseCompatLoadingForDrawables")
    override fun convert(holder: BaseViewHolder, item: Group) {
        holder.setText(R.id.tv_title, "${item.name}")
        if (item.name == "未分组") {
            holder.setText(R.id.edit, "分组")
        } else {
            holder.setText(R.id.edit, "编辑")
        }
        var studentAdapter = StudentAdapter(item.student)
        holder.getView<RecyclerView>(R.id.rv).adapter = studentAdapter
        studentAdapter.setOnItemClickListener { adapter, view, position ->
            student(studentAdapter.data[position])
        }
    }
    init {
        addChildClickViewIds(R.id.edit)
    }
}
